package BinaryTreeTraversal;

public class Traverse {
    public static void main(String[] args) {
        Node nodeA = new Node("A");
        Node nodeB = new Node("B");
        Node nodeC = new Node("C");
        Node nodeD = new Node("D");
        Node nodeE = new Node("E");
        Node nodeF = new Node("F");
        Node nodeG = new Node("G");

        nodeA.left = nodeB;
        nodeA.right = nodeC;
        nodeB.left = nodeD;
        nodeB.right = nodeE;
        nodeE.left = nodeG;
        nodeC.right = nodeF;

        System.out.println("先序遍历为：");
        preOrder(nodeA);
        System.out.println();
        System.out.println("中序遍历为");
        inOrder(nodeA);
        System.out.println();
        System.out.println("后续遍历为");
        postOrder(nodeA);

    }

    public static void preOrder(Node root){
        if(root==null)  return;
        System.out.print(root.value);
        preOrder(root.left);
        preOrder(root.right);
    }
    public static void inOrder(Node root){
        if(root==null)  return;
        inOrder(root.left);
        System.out.print(root.value);
        inOrder(root.right);
    }
    public static void postOrder(Node root){
        if(root==null)  return;
        postOrder(root.left);
        postOrder(root.right);
        System.out.print(root.value);
    }
}
